<%- content_for :title do -%>
  リスト
<%- end -%>

<%- content_for :head do -%>
<%= stylesheet_link_tag 'tasks', :media => :all %>
<%= javascript_include_tag 'prototype' %>
<%= javascript_include_tag 'common' %>
<script type="text/javascript">
  Event.observe(window, 'load', function(event) {
    var teamSelect = $('team-select');
    teamSelect.observe('change', function(event) {
      location.href = location.href.addQueryParams({
        team: teamSelect.value,
        member: 'all'
      });
    });

    var memberSelect = $('member-select');
    memberSelect.observe('change', function(event) {
      location.href = location.href.addQueryParams({
        member: memberSelect.value
      });
    });

  });
</script>
<%- end -%>

<%= render :partial => 'navigation' %>

<%-
  begin_at = @date.beginning_of_month
  end_at = @date.end_of_month
-%>
<div class="list">
  <% if @view == :all && !@member %>
    <div class="member-list">
      <table>
        <%- task_count = 0 -%>
        <% @tasks.each do |task| %>
          <% if task_count % 10 == 0 %>
            <tr>
              <th class="corner"></th>
              <% each_days(begin_at, end_at) do |date| %>
                <th class="<%=h day_cell_classes(date, @date).join(" ") %>">
                  <a href="<%= new_task_url('task[formatted_begin_at]' => date.strftime('%Y/%m/%d'), 'task[formatted_end_at]' => date.strftime('%Y/%m/%d')) %>" title="この日のタスクを作成する"><% if date.day < 10 %><span style="visibility:hidden">0</span><% end %><%=h date.day %></a>
                </th>
              <% end %>
            </tr>
            <% reset_cycle('default') %>
          <% end %>
          <%- task_count += 1 -%>
          <tr class="task task-<%=h cycle(1, 2) %>">
            <td class="name"><%= link_to h(task.title), task_url(task) %></td>
            <% each_active_days_in_task(task, begin_at, end_at) do |date, active| %>
              <td<% if active %> class="active"<% end %>></td>
            <% end %>
          </tr>
        <% end %>
      </table>
    </div>
  <% else %>
    <% @users.each do |user, tasks| %>
      <div class="member-list">
        <% if !@member %>
          <div class="member">
            <%= link_to h(user.name), link_params(:member => user.id)  %>
          </div>
        <% end %>
        <table>
          <%- task_count = 0 -%>
          <% tasks.each do |task, periods| %>
            <% if task_count % 10 == 0 %>
              <tr>
                <th class="corner"></th>
                <% each_days(begin_at, end_at) do |date| %>
                  <th class="<%=h day_cell_classes(date, @date).join(" ") %>">
                    <a href="<%= new_task_url('workers' => user.name, 'task[formatted_begin_at]' => date.strftime('%Y/%m/%d'), 'task[formatted_end_at]' => date.strftime('%Y/%m/%d')) %>" title="この日のタスクを作成する"><% if date.day < 10 %><span style="visibility:hidden">0</span><% end %><%=h date.day %></a>
                  </th>
                <% end %>
              </tr>
              <% reset_cycle('default') %>
            <% end %>
            <%- task_count += 1 -%>
            <tr class="task task-<%=h cycle(1, 2) %>">
              <td class="name"><%= link_to h(task.title), task_url(task) %></td>
              <% each_active_days(periods, begin_at, end_at) do |date, active| %>
                <td<% if active %> class="active"<% end %>></td>
              <% end %>
            </tr>
          <% end %>
        </table>
      </div>
    <% end %>
  <% end %>
</div>